import os

import gradio as gr
from openai import OpenAI

openai_api_key = "EMPTY"
openai_api_base = "http://localhost:10086/v1"
client = OpenAI(
        api_key=openai_api_key,
        base_url=openai_api_base,
    )

def infer(query):

    chat_response = client.chat.completions.create(
        # model="domain_model",
        model="lora",
        messages=[
            {"role": "user", "content": query},
        ],
        max_tokens=16,
    )

    return f"{chat_response.choices[0].message.content}"


def greet(query):
    return "domain: " + infer(query)

demo = gr.Interface(
    fn=greet,
    inputs=["text"],
    outputs=[gr.Textbox(label="domain", lines=3)],
    title="Domain Classify Demo",
    description="输入句子，返回句子的类别",
    examples=["打开车窗","播放音乐","导航回家","哈哈哈哈","明天南京有雨吗"]
)

demo.launch(server_name="0.0.0.0",server_port=10086)



# if __name__ == "__main__":
#     demo = gr.ChatInterface(infer).queue()
#     demo.launch(share=True, server_name="0.0.0.0")
